<%@ page language="java" pageEncoding="UTF-8"%>
<%@ include file="/jsp/common/headMain.jsp" %>

<html>
  <head>
    <base href="<%=basePath%>">
  </head>
  		<script type="text/javascript">
		$(function(){
				jQuery("#_groupGrid").jqGrid({
				   	url: "${base}/group_getList",
					datatype: "json",
				   	colNames:['ID','用户组名称','角色设置','用户设置','编辑'],
				   	colModel:[
				   		{name:'id',index:'id', width:55, align:'center',hidden:true},
				   		{name:'groupname', index:'groupname', align:'center'},
				   		{name:'rolesetup', index:'rolesetup', align:'center'},
				   		{name:'usersetup', index:'usersetup', align:'center'},
				   		{name:'edit', index:'edit', align:'center'},
				   	],
				   	width:900,
				   	height:230,
				   	rowNum:10,
				   	rowList:[10,20,30],
				   	pager: '#_groupBar',
				   	sortname: 'id',
				    viewrecords: true,
				    sortorder: "desc",
					multiselect: false,
					jsonReader: {
						repeatitems : false
					},
					rownumbers : true,
					caption: "用户组管理",
					afterInsertRow : function(rowid, data) {
						$("#_groupGrid").jqGrid('setCell', rowid, 'rolesetup', '<span style="cursor:pointer;" onclick="_groupSetupRole(' + data.id + ');">角色设置</span>', {color : 'purple'});
						$("#_groupGrid").jqGrid('setCell', rowid, 'usersetup', '<span style="cursor:pointer;" onclick="_groupSetupUser(' + data.id + ');">用户设置</span>', {color : 'purple'});
						$("#_groupGrid").jqGrid('setCell', rowid, 'edit', '修改|&nbsp;<span style="cursor:pointer;" onclick="_delGroup(' + data.id + ');">删除</span>', {color:'green'});
					}
				});
				jQuery("#_groupGrid").jqGrid('navGrid','#_groupBar',{add : false, del : false, edit : false, refresh : true, search : false});
				jQuery.div.util.dialogInit("增加/编辑商家信息", "addOrUpdateGroup", 500, 450);
		});
		function _addOrUpdateGroup(){
			$('#addOrUpdateGroup').dialog('open').load('${base}/group_addOrUpdateGroup', function(){
				jQuery.div.util.hideLoading();
			});
			//window.location.href="${base}/group_addOrUpdateGroup";
		}
		//用户组设置角色
		function _groupSetupRole(groupId){
			window.location.href="${base}/group_groupSetupRole/"+groupId;
		}
		//用户组设置用户
		function _groupSetupUser(){
			window.location.href="${base}/group_groupSetupUser";
		}
		function _delGroup(id) {
			if (confirm("删除用户组吗？")) {
				$.post("${base}/group_deleteGroup/" + id, 
					function(data) {
						if (data && data.success) {
							alert(data.msg);
							$("#_groupGrid").jqGrid('setGridParam',{url: '${base}/group_getList'}).trigger("reloadGrid");
						} else {
							alert(data.msg);
						}
					}, 
				"json");
			}
		}
		</script>
	<body>
	<table cellpadding="0" cellspacing="0" border="0" width="99%" style="height:100%;">
		<tr><td style="height:10px; overflow:hidden;" colspan="2"></td></tr>
		<tr>
			<!--右边内容-->
			<td width="*" valign="top" class="contList">
				<div id="_groupManagerDiv">
					<!-- 显示商家列表 --> 
						<table id="_groupGrid"></table>
						<div id="_groupBar"></div>
						<div class="contBtn" style="width:900px; _width:902px;"><!--width 和id="_GroupGrid"宽度设置一致;IE宽度需多加左右border的宽度-->
							<input type="button" value="增加用户组" class="btn" onclick="_addOrUpdateGroup();"/>
						</div>
				</div>
				
			</td>
	</table>
	<div id="addOrUpdateGroup"></div><!--角色设置模块-->
	</body>
</html>
